########################################################################
# Table 2: Descriptive statistics of macropartisanship in each country #
########################################################################

#library
library(tidyverse)
library(psych)

#reload each data

usam<-read.csv("usa_macropartisanship.csv")
ukm<-read.csv("uk_macropartisanship.csv")
germanm<-read.csv("german_macropartisanship.csv")
denmarkm<-read.csv("denmark_macropartisanship.csv")
japanm<-read.csv("japan_macropartisanship.csv")

#change colnames
colnames(usam)<-c("","yearMon","mp1","USA")
usam<-usam[,-1]
colnames(ukm)<-c("","yearMon","mp1","UK")
ukm<-ukm[,-1]
colnames(germanm)<-c("","yearMon","mp1","German")
germanm<-germanm[,-1]
colnames(denmarkm)<-c("","yearMon","mp1","Denmark")
denmarkm<-denmarkm[,-1]
colnames(japanm)<-c("","yearMon","mp1","Japan")
japanm<-japanm[,-1]

#unified 5 datasets
df_1<-left_join(usam,ukm,by="yearMon")
df_2<-left_join(df_1,germanm,by="yearMon")
df_3<-left_join(df_2,denmarkm,by="yearMon")
df_unified<-left_join(df_3,japanm,by="yearMon")

#resetting dataframe
df_mp<-data.frame(df_unified$yearMon,df_unified$Denmark,
                  df_unified$German,df_unified$Japan,
                  df_unified$UK,df_unified$USA)

#resetting colnames

colnames(df_mp)<-c("yearMon","DEN","GER","JPN","UK","USA")
des_dfmp<-describe(df_mp,ranges=F,trim = F)
xtable(des_dfmp)
summary(df_mp)
describe(df_mp)